
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8"%>
<%@taglib prefix="mvc" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="fmt" uri="http://www.springframework.org/tags" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <title>新建考核任务试卷</title>
    <link rel="stylesheet" href="/lib/pagination/style/pagination.css">
    <link rel="stylesheet" href="/css/base/base.css?20201106.1">
    <link rel="stylesheet" href="/css/notice/noticeManagement.css">
    <link rel="stylesheet" href="/lib/laydate/need/laydate.css">
    <script type="text/javascript" src="/js/jquery/jquery-1.9.1.js"></script>
    <script src="/js/common/language.js"></script>
    <script src="/js/jquery/jquery.cookie.js"></script>
    <script src="/js/base/base.js"></script>
    <script src="/lib/laydate/laydate.js"></script>
    <script src="/lib/pagination/js/jquery.pagination.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.ui.widget.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.iframe-transport.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/jQuery-File-Upload-master/jquery.fileupload.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.config.js" type="text/javascript" charset="utf-8"></script>
    <script src="/lib/ueditor/ueditor.all.js" type="text/javascript" charset="utf-8"></script>
    <script src="../../lib/layer/layer.js?20201106"></script>
    <%--<script src="../js/jquery/jquery.cookie.js"></script>--%>
    <script src="/lib/jquery.form.min.js"></script>
    <script type="text/javascript" src="/js/common/fileupload.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/commonTheme/${sessionScope.InterfaceModel}/commonTheme.css"/>
    <style>

        input{
            float: none;
        }
        .editAndDelete3{
            color: red;
        }
        .bar {
            height: 18px;
            background: green;
        }
        select{
            width: 228px !important;
            padding-left: 10px;
        }
        .newClass{
            float: right;
            width: 90px;
            height: 28px;
            background: url(../../img/file/cabinet01.png) no-repeat;
            color: #fff;
            font-size: 14px;
            line-height: 28px;
            margin: 2% 2% 0 0;
            cursor: pointer;
        }
        .del{
            color: red;
        }
        /**去掉数字的上下箭头*/
        input::-webkit-outer-spin-button, input::-webkit-inner-spin-button {
            -webkit-appearance: none;
        }
        input[type="number"] {
            -moz-appearance: textfield;
        }

    </style>
    <script src="/lib/ueditor/UEcontroller.js" type="text/javascript" charset="utf-8"></script>

    <script>

    </script>
</head>
<body>
<div class="navigation">
    <img src="/img/commonTheme/${sessionScope.InterfaceModel}/newsManages2_1.png" alt="">
    <h2 class="head_title">新建考核试卷</h2>
    <div class="newClass" id="newClass">
            <span style="margin-left: 30px;">
                <%--<img style="margin-right: 4px;margin-left: -11px;margin-bottom: 2px;" src="../../img/mywork/newbuildworjk.png" alt="">--%>
                返回
            </span>
    </div>
</div>
<div id="pagediv" class="tableMain">
    <%--<form id="ajaxform" action="/Hr/Incentive/addHrIncentive">--%>
    <table>
        <tbody>
        <tr>
            <td class="blue_text" width="20%">
                考核任务标题：
            </td>
            <td width="80%" style="text-align: left">
                <input style="width: 228px" type="text" name="paperName" id="paperName">
            </td>
        </tr>
        <tr class="cicle">
            <td class="blue_text" width="20%">考核指标集：</td>
            <td width="80%" style="text-align: left">
                <select name="postPriv" class="groups1">
                    <option value="">请选择</option>
                </select>
                <label style="margin:0 6px">权重:</label><input type="number" style="width: 88px;height: 30px;border: 1px solid #ccc;" onblur="clearNoNum(this)" onmousewheel="stopScrollFun()" onDOMMouseScroll="stopScrollFun()" placeholder="请输入小数" value="" class="addgro"/>
                <button onclick="addgroup($(this))" class="vall">添加</button>
                <button onclick="delTable($(this))" class="">删除</button>
            </td>
        </tr>
        <%--<tr>--%>
            <%--<td class="blue_text" width="20%">--%>
                <%--<fmt:message code="notice.th.reminder"/>：--%>
            <%--</td>--%>
            <%--<td width="80%" style="text-align: left" id="thing">--%>
                <%--<input type="checkbox" class="remind" checked value="0">--%>
                <%--<span><fmt:message code="notice.th.remindermessage"/></span>--%>
                <%--&lt;%&ndash;<input type="hidden" name="howRenind" >&nbsp;&ndash;%&gt;--%>
                <%--<input type="checkbox" class="smsRemind" value="1">--%>
                <%--<span><fmt:message code="vote.th.UseRemind"/></span>--%>
                <%--&lt;%&ndash;<input type="hidden" name="smsDefault" value="1">&ndash;%&gt;--%>
            <%--</td>--%>
        <%--</tr>--%>
        <tr>
            <td colspan="2" style="padding: 18px;">
                描述：
                <div id="word_container" name="incentiveDescription">

                </div>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align: center" class="btnarr">
                <a href="javascript:;" class="savebtn"><fmt:message code="global.lang.save"/></a>
            </td>
        </tr>
        </tbody>
    </table>
    <%--</form>--%>
</div>
<script>
    var strr;
    ue = UE.getEditor('word_container',{elementPathEnabled : false});
    $.ajax({
        type:'get',
        url:'/ScoreGroupController/selScoreGroup',
        dataType:'json',
        data:{
            typeId:0,
        },
        success:function(res){
            var str='';
            if(res){
                $.each(res.obj,function(index,item){
                    str+='<option value="'+item.groupId+'">'+item.groupName+'</option>'
                });
                $('.groups1').append(str);
            }
        }
    });
    //验证
    function mustWrite() {
        if ($('#paperName').val() == "") {
            $.layerMsg({content: '考核任务标题！', icon: 2});
            return false;
        }
        // if ($('#groups').val() == "") {
        //     $.layerMsg({content: '请选择考核指标集！', icon: 2});
        //     return false;
        // }
        // if ($('#department').val() == "") {
        //     $.layerMsg({content: '请选择考核人！', icon: 2});
        //     return false;
        // }
    }
    function inputcheck(name,value) {
        $('#'+name+'').val(value)
    }
    //截取字符串
    function getRequest() {
        var url = window.location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for(var i = 0; i < strs.length; i ++) {

                theRequest[strs[i].split("=")[0]]=decodeURI(strs[i].split("=")[1]);

            }
        }
        return theRequest;
    }
    var num=$(".groups")+1;
    function addgroup() {
        var tableN = $("#pagediv tr td").find("select[name=postPriv]");
        var num = $(tableN).eq(tableN.length-1).attr("class");
        var nb =  Number(num.substr(num.length-1,1))+1;
        var gro = ".groups"+nb;
        var str2 = '<tr class="cicle">' +
            '<td class="blue_text" width="20%"></td>' +
            '<td width="80%" style="text-align: left">' +
            '<select name="postPriv" class="groups'+nb +'">' +
            // '<option value="">请选择</option>' +
            '</select>' +
            '<label style="margin:0 6px">权重:</label><input type="number" style="width: 88px;height: 30px;border: 1px solid #ccc;" onblur="clearNoNum(this)" onmousewheel="stopScrollFun()" onDOMMouseScroll="stopScrollFun()" placeholder="请输入小数" value="" class="addgro"/>'+
            // '<button onclick="addgroup($(this))" class="vall">添加</button>' +
            '</td>' +
            '</tr>';
        $(".cicle").eq($(".cicle").length-1).after(str2)
        $.ajax({
            type:'get',
            url:'/ScoreGroupController/selScoreGroup',
            dataType:'json',
            data:{
                typeId:0,
            },
            success:function(res){
                var str='<option value="">请选择</option>';
                if(res){
                    $.each(res.obj,function(index,item){
                        str+='<option value="'+item.groupId+'">'+item.groupName+'</option>'
                    });
                    $(gro).html(str);
                }
                // var oSelect = document.getElementByclassName(groups).options.length;
                // console.log(oSelect)
            }
        });

    }
    var flowId= getRequest().flowId;
    var type= getRequest().type;
    // 查询提醒权限
    // $.ajax({
    //     type:'get',
    //     url:'/smsRemind/getRemindFlag',
    //     dataType:'json',
    //     data:{
    //         type:15
    //     },
    //     success:function (res) {
    //         if(res.flag){
    //             if(res.obj.length>0){
    //                 var data = res.obj[0];
    //                 // 是否默认发送
    //                 if(data.isRemind=='0'){
    //                     $('.remind').prop("checked", false);
    //                 }else if(data.isRemind=='1'){
    //                     $('.remind').prop("checked", true);
    //                 }
    //                 // 是否手机短信默认提醒
    //                 if(data.isIphone=='0'){
    //                     $('.smsRemind').prop("checked", false);
    //                 } else if (data.isIphone=='1'){
    //                     $('.smsRemind').prop("checked", true);
    //                 }
    //                 // 是否允许发送事务提醒
    //                 if(data.isCan=='0'){
    //                     $('.remind').prop("checked", false);
    //                     $('.smsRemind').prop("checked", false);
    //                     $('#thing').parent('tr').hide();
    //                 }
    //
    //             }
    //         }
    //     }
    // })
    if(type==0){
        // $.ajax({
        //     type: 'post',
        //     url: '/ScoreFlowController/selScoreFlow',
        //     dataType: 'json',
        //     data: {
        //         flowId:flowId
        //     },
        //     success: function (res) {
        //         var objs=  res.obj[0]
        //         inputcheck('budgetItemNo',objs.flowTitle)
        //         inputcheck('department',objs.rankmanName)
        //         inputcheck('itemExecuter',objs.participantName)
        //         inputcheck('itemManager',objs.viewUserName)
        //         inputcheck('newpriveItem',objs.groupId)
        //         inputcheck('newbudgetItemBegintime',objs.beginDateStr)
        //         inputcheck('newbudgetItemEndtime',objs.endDateStr)
        //         if(objs.remind=='0'){
        //             $('.remind').prop("checked", false);
        //         }else if(objs.remind=='1'){
        //             $('.remind').prop("checked", true);
        //         }
        //         if(objs.smsRemind=='0'){
        //             $('.smsRemind').prop("checked", false);
        //         } else if (objs.smsRemind=='1'){
        //             $('.smsRemind').prop("checked", true);
        //         }
        //         ue.ready(function(){
        //             ue.setContent(objs.flowDesc);
        //         });
        //         $('.head_title').html("修改考核任务管理");
        //     }
        // })
        // $('.savebtn').click(function () {
        //     if (mustWrite() == false) {
        //         return;
        //     }
        //     var html = ue.getContent();
        //     var budgetItemNo = $('#budgetItemNo').val();
        //     /*var department = $('#department').val().slice(0,$('#department').val().length-1);*/
        //     var itemExecuter = $('#itemExecuter').attr("user_id");
        //     var department = $('#department').attr("user_id");
        //     var itemManager = $('#itemManager').attr("user_id");
        //     /*console.log(itemExecuter);*/
        //     // var itemExecuter = $('#itemExecuter').val().slice(0,$('#itemExecuter').val().length-1);
        //     /* var itemManager = $('#itemManager').val().slice(0,$('#itemManager').val().length-1);*/
        //     var priveItem = $('#newpriveItem option:selected').val();
        //     var budgetItemBegintime = $('#newbudgetItemBegintime').val();
        //     var budgetItemEndtime = $('#newbudgetItemEndtime').val();
        //     $.ajax({
        //         url: '/ScoreFlowController/modifyScoreFlow',
        //         type: 'post',
        //         data: {
        //             flowId:flowId,
        //             flowTitle: budgetItemNo,
        //             rankman: department,
        //             participant: itemExecuter,
        //             viewUserId: itemManager,
        //             groupId: priveItem,
        //             beginDate:budgetItemBegintime,
        //             endDate:budgetItemEndtime,
        //             beginDateStr: budgetItemBegintime,
        //             endDateStr: budgetItemEndtime,
        //             flowDesc: html,
        //             remind:function(){
        //                 if($('.remind').prop('checked')==false){
        //                     return '0';
        //                 }else {
        //                     return '1';
        //                 }
        //             },
        //             smsRemind:function(){
        //                 if($('.smsRemind').prop('checked')==false){
        //                     return '0';
        //                 }else {
        //                     return '1';
        //                 }
        //             }
        //         },
        //         dataType: 'json',
        //         success: function (res) {
        //             if (res.msg == "新建项目重复") {
        //                 layer.msg("新建项目重复", {
        //                     icon: 2,
        //                     time: 1500 //2秒关闭（如果不配置，默认是3秒）
        //                 });
        //             } else {
        //                 layer.msg("修改成功", {
        //                     icon: 1,
        //                     time: 1500 //2秒关闭（如果不配置，默认是3秒）
        //                 }, function () {
        //                     location.href = "/ScoreFlowController/assessmentTaskment"
        //                 });
        //             }
        //         }
        //     })
        // })
    }else{
        //点击保存
        $('.savebtn').click(function () {
            // var str = $(".vall").attr("data-title");
            var list = [];
            $("#pagediv tr td").find("select[name=postPriv] option:selected").each(function(){
                if($(this).val()==""){
                    list.push(0);
                }else{
                    list.push($(this).val());
                }
            });
            var list1=[];
            $("#pagediv tr td").find(".addgro").each(function(){
                if($(this).val()==""){
                    list1.push(0);
                }else{
                    list1.push($(this).val());
                }
            });
            var tyuu="";
            var total=[];
            for(var j=0;j<list.length;j++){
                total.push(list[j]+'|'+list1[j]);
            }
            for(var z=0;z<total.length;z++){
                if(total[z]=="0|0"){
                }else{
                    tyuu+= total[z]+","
                }
            }
            if (mustWrite() == false) {
                return;
            }
            var html = ue.getContent();
            var paperName = $('#paperName').val();
            $.ajax({
                url: '/scorePaper/insert',
                type: 'post',
                data: {
                    paperName: paperName,
                    groups:tyuu,
                    info: html,
                    // remind:function(){
                    //     if($('.remind').prop('checked')==false){
                    //         return '0';
                    //     }else {
                    //         return '1';
                    //     }
                    // },
                    // smsRemind:function(){
                    //     if($('.smsRemind').prop('checked')==false){
                    //         return '0';
                    //     }else {
                    //         return '1';
                    //     }
                    // }
                },
                dataType: 'json',
                success: function (res) {
                    if (res.msg == "新建项目重复") {
                        layer.msg("新建项目重复", {
                            icon: 2,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        });
                    } else {
                        layer.msg("新建成功", {
                            icon: 1,
                            time: 1500 //2秒关闭（如果不配置，默认是3秒）
                        }, function () {
                            location.href = "/scorePaper/index"
                        });
                    }
                }
            })
        })
    }


    //下拉列表

    //添加人员
    $('.adddept').click(function(){
        user_id='department';
        /*$.popWindow("../../common/roleMapper");*/
        $.popWindow("../../common/selectUser");
    })
    $('.add3').click(function(){
        user_id='itemManager';
        $.popWindow("../../common/selectUser");
    })
    $('.add4').click(function(){
        user_id='itemExecuter';
        $.popWindow("../../common/selectUser");
    })
    $('.clear').click(function(){
        $(this).siblings().find('input').removeAttr('deptname').removeAttr('deptno').removeAttr('deptid').removeAttr('user_id').val('')
    })
    // 清空人员信息
    // $('.clear3').click(function () {
    //     $('#itemManager').attr("privid", "");
    //     $('#itemManager').attr("userpriv", "");
    //     $('#itemManager').attr("user_id", "");
    //     $('#itemManager').val("");
    // });
    // $('.clear').click(function () {
    //     $('#department').attr("privid", "");
    //     $('#department').attr("userpriv", "");
    //     $('#department').attr("user_id", "");
    //     $('#department').val("");
    // });
    // $('.clear4').click(function () {
    //     $('#itemExecuter').attr("privid", "");
    //     $('#itemExecuter').attr("userpriv", "");
    //     $('#itemExecuter').attr("user_id", "");
    //     $('#itemExecuter').val("");
    // });
    var user_id='';
    ue = UE.getEditor('word_container',{elementPathEnabled : false});
    UEimgfuc();
    // 删除表格行
    function delTable(elem){
        // $("#pagediv tr td").find("select[name=postPriv]"
        var trs = $("#pagediv").find('.cicle');
        var trslen = trs.length
        $(trs).parents("tr").remove();
        if(trslen>1) $(trs[trslen-1]).remove()
    }
    // 输入数字限制鼠标滚动方法
    function stopScrollFun(evt) {
        evt = evt || window.event;
        if(evt.preventDefault) {
            // Firefox
            evt.preventDefault();
            evt.stopPropagation();
        } else {
            // IE
            evt.cancelBubble=true;
            evt.returnValue = false;
        }
        return false;
    }
    function clearNoNum(obj) {
        obj.value = obj.value.replace(/[^\d.]/g, "");  //清除“数字”和“.”以外的字符
        obj.value = obj.value.replace(/\.{2,}/g, "."); //只保留第一个. 清除多余的
        obj.value = obj.value.replace(".", "$#$").replace(/\./g, "").replace("$#$", ".");
        obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3');//只能输入两个小数
        if (obj.value.indexOf(".") < 0 && obj.value != "") {//以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
            obj.value = parseFloat(obj.value);
        }
    }
    $(function () {
        $('input[name="salaryMonth"]').val(queryTime());
        fileuploadFn('#uploadinputimg', $('#files_txt'));
//    返回
            $('.newClass').click(function(){
                location.href="/scorePaper/index"
            })
        //删除附件
        function deleteChatment(data, element) {

            layer.confirm('<fmt:message code="workflow.th.que" />？', {
                btn: ['<fmt:message code="global.lang.ok" />', '<fmt:message code="depatement.th.quxiao" />'], //按钮
                title: "<fmt:message code="notice.th.DeleteAttachment" />"
            }, function () {
                //确定删除，调接口
                $.ajax({
                    type: 'get',
                    url: '/delete',
                    dataType: 'json',
                    data: data,
                    success: function (res) {

                        if (res.flag == true) {
                            layer.msg('<fmt:message code="workflow.th.delsucess" />', {icon: 6});
                            element.remove();
                        } else {
                            layer.msg('<fmt:message code="lang.th.deleSucess" />', {icon: 6});
                        }
                    }
                });

            }, function () {
                layer.closeAll();
            });
        }
        function queryTime() {
            function p(s) {
                return s < 10 ? '0' + s : s;
            }

            var myDate = new Date();
            //获取当前年
            var year = myDate.getFullYear();
            //获取当前月
            var month = myDate.getMonth() + 1;
            //获取当前日
            var date = myDate.getDate();
            var h = myDate.getHours();       //获取当前小时数(0-23)
            var m = myDate.getMinutes();     //获取当前分钟数(0-59)
            var s = myDate.getSeconds();
//        var now=year+'-'+p(month)+"-"+p(date)+" "+p(h)+':'+p(m)+":"+p(s);
            var now = year + '-' + p(month);
//        if(type==undefined){
//            return now;
//        }else {
//            return year+'-'+p(month)+"-"+p(date)
//        }
            return now;


        }
        // 用正则表达式获取地址栏参数
        function GetQueryString(name) {
            var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);

            if (r != null) {
                return unescape(r[2]);
            } else {
                return null;
            }
        }
    })
</script>
</body>
</html>